<template>
	<view class="goods">
		<scroll-view
			scroll-y="true" 
			class="scroll"
			@scrolltolower="refresh()" 
		>
			<view class="con">
				<goods-list :goodsList="goodsList"></goods-list>
				<uni-load-more :status="loadMoreStatus"></uni-load-more>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import goodsList from '@/components/goods-list/goods-list.vue'
	import {getGoodsList,getGoodsListFromNews} from '../../api/index/index.js'
	export default {
		components:{
			goodsList,
		},
		data() {
			return {
				page:1,
				goodsList:[],
				loadMoreStatus:'loading',
				id:null,
				type:null
			}
		},
		methods: {
			async getGoods(){
				const {data:res}=await getGoodsList(this.page,this.id)
				if(this.page==1){
					this.goodsList = res
				}else{
					this.goodsList = this.goodsList.concat(res)
				}
				this.page++
			},
			async getNewsGoods(){
				const {data:res}=await getGoodsListFromNews(this.id,this.page)
				if(this.page==1){
					this.goodsList = res
				}else{
					this.goodsList = this.goodsList.concat(res)
				}
				this.page++
			},
			refresh(){
				if(this.type==1){
					this.getNewsGoods()
				}else{
					this.getGoods()
				}
			}
		},
		onLoad(options) {
			this.id= options.id
			this.type= options.type
			if(options.title){
				uni.setNavigationBarTitle({
					title: options.title
				})
			}
			this.refresh()
			
		}
	}
</script>

<style lang="stylus" scoped>
.goods
	height 100%
	.scroll
		height: 750px;
</style>
